/**
 * Created by cxj on 2016/2/22.
 */
var grid;
define([
    "jquery",
    "IO",
    "bootbox"
], function($,IO,bootbox) {
    $(function () {

        //每列数据列性
        var columns = [

            {title : '编号',dataIndex :'User_ID',dataSource:function(data,datarow,gridobj,current_column) {

                return "<span>"+parseInt( (gridobj.current_page-1)*gridobj.page_rows+parseInt(datarow)+1)+"</span>";
            }},
            { title: '短信id', dataIndex: 'sms_id',},
            { title: '手机号', dataIndex: 'mobile',},
            { title: 'app', dataIndex: 'type',dataSource: function (data, datarow, gridobj, current_column) {
                var type = data[datarow].type;
                if(type>=0 && type <=2)
                    return  "用户端";
                if(type>=3 && type <=5)
                    return  "工人端";

            }},
            { title: '类型', dataIndex: 'type',dataSource: function (data, datarow, gridobj, current_column) {
                  var type = data[datarow].type;
                  if(type==0)
                      return  "注册验证";
                  if(type==1)
                    return  "登录验证";
                  if(type==2)
                    return  "重置密码验证";
                 if(type==3)
                    return  "注册验证";
                 if(type==4)
                     return  "登录验证";
                  if(type==5)
                    return  "重置密码验证";

            }},
            { title: '有效标志', dataIndex: 'cap_valid',dataSource: function (data, datarow, gridobj, current_column) {
                var cap_valid = data[datarow].cap_valid;

                //return cap_valid;
                if(cap_valid==0)
                    return  "";
                if(cap_valid==1)
                {
                    if(getNowFormatDate()<data[datarow].expire_time)
                        return  "有效";

                    return "";
                }

            }},
            { title: '验证码', dataIndex: 'cap_code',},
            { title: '发送时间', dataIndex: 'create_time',},
            { title: '过期时间', dataIndex: 'expire_time',},


        ];


        //数组初始化

        function dataInit() {
            grid = new Grid("/sms/getsmslist", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 20);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {

            var param="mobile="+$("#mobile").val()+"&type="+$("#type").val();

            return param;

        }
        dataInit();
        //查询
        $("#query").bind("click", function () {
            dataInit();
        });
    });


});